package com.ruoyi.project.stat.paeaReportBusiness.controller;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.project.stat.paeaReportBusiness.domain.StatisticsReportBusiness;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.stat.paeaReportBusiness.domain.PaeaReportBusiness;
import com.ruoyi.project.stat.paeaReportBusiness.service.IPaeaReportBusinessService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 差错处理统计Controller
 *
 * @author gang.wei
 * @date 2020-04-14
 */
@Controller
@RequestMapping("/stat/paeaReportBusiness")
public class PaeaReportBusinessController extends BaseController
{
    private String prefix = "stat/paeaReportBusiness";

    @Autowired
    private IPaeaReportBusinessService paeaReportBusinessService;

    @RequiresPermissions("stat:paeaReportBusiness:view")
    @GetMapping()
    public String paeaReportBusiness(ModelMap mmap)
    {
        paeaReportBusinessService.init(mmap);
        return prefix + "/paeaReportBusiness";
    }

    /**
     * 查询差错处理统计列表
     */
    @RequiresPermissions("stat:paeaReportBusiness:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list()
    {
        startPage();
        return getDataTable(new ArrayList<PaeaReportBusiness>());
    }
    /**
     * 查询差错处理统计列表
     */
    @RequiresPermissions("stat:paeaReportBusiness:query")
    @PostMapping("/query")
    @ResponseBody
    public TableDataInfo query(Date beginOperateDate, Date endOperateDate, String orgCode, int statType, String userRoles)
    {
        //startPage();
        List<StatisticsReportBusiness> statisticsReportBusinesses =
                paeaReportBusinessService.queryBusiness(beginOperateDate,endOperateDate,orgCode,statType,userRoles);
        return getDataTable(statisticsReportBusinesses);
    }
    /**
     * 导出差错处理统计列表
     */
    @RequiresPermissions("stat:paeaReportBusiness:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaReportBusiness paeaReportBusiness)
    {
        List<PaeaReportBusiness> list = paeaReportBusinessService.list(new QueryWrapper<>(paeaReportBusiness));
        ExcelUtil<PaeaReportBusiness> util = new ExcelUtil<PaeaReportBusiness>(PaeaReportBusiness.class);
        return util.exportExcel(list, "paeaReportBusiness");
    }

    /**
     * 新增差错处理统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存差错处理统计
     */
    @RequiresPermissions("stat:paeaReportBusiness:add")
    @Log(title = "差错处理统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaReportBusiness paeaReportBusiness)
    {
        return toAjax(paeaReportBusinessService.saveOrUpdate(paeaReportBusiness));
    }

    /**
     * 修改差错处理统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaReportBusiness paeaReportBusiness = paeaReportBusinessService.getById(id);
        mmap.put("paeaReportBusiness", paeaReportBusiness);
        return prefix + "/edit";
    }

    /**
     * 修改保存差错处理统计
     */
    @RequiresPermissions("stat:paeaReportBusiness:edit")
    @Log(title = "差错处理统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaReportBusiness paeaReportBusiness)
    {
        return toAjax(paeaReportBusinessService.saveOrUpdate(paeaReportBusiness));
    }

    /**
     * 删除差错处理统计
     */
    @RequiresPermissions("stat:paeaReportBusiness:remove")
    @Log(title = "差错处理统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaReportBusinessService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
